//package com.training.controller;
//
//import com.training.dto.ProgressRecordDto;
//import com.training.entity.LearningProgress;
//import com.training.entity.Student;
//import com.training.service.LearningProgressService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import javax.servlet.http.HttpSession;
//import java.util.Optional;
//
//@RestController
//@RequestMapping("/api/progress")
//public class LearningProgressController {
//
//    @Autowired
//    private LearningProgressService progressService;
//
//    @PostMapping("/record")
//    public ResponseEntity<Void> recordProgress(@RequestBody ProgressRecordDto progressDto, HttpSession session) {
//        Student student = (Student) session.getAttribute("student");
//        if (student == null) {
//            return ResponseEntity.status(401).build(); // Unauthorized
//        }
//
//        progressService.recordProgress(
//                student.getId(),
//                progressDto.getCourseId(),
//                progressDto.getChapterId(),
//                progressDto.getProgressSeconds()
//        );
//        return ResponseEntity.ok().build();
//    }
//
//    @GetMapping("/chapter/{chapterId}")
//    public ResponseEntity<LearningProgress> getProgress(@PathVariable Long chapterId, HttpSession session) {
//        Student student = (Student) session.getAttribute("student");
//        if (student == null) {
//            return ResponseEntity.status(401).build(); // Unauthorized
//        }
//
//        Optional<LearningProgress> progress = progressService.getProgress(student.getId(), chapterId);
//        return progress.map(ResponseEntity::ok)
//                .orElse(ResponseEntity.notFound().build());
//    }
//}
